package com.muchenxinxi.androidbaseapp.utils;

import java.io.File;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;

/**
 * ┏--------------------
 * │        /) /)
 * │     ฅ(• ﻌ •)ฅ
 * │  Created by HaoKing on 2016/12/4.
 * │  www.muchenxinxi.com
 * │  www.nextdever.com
 * │  QQ:773693552
 * │  QQ群: Geek Chat 344386592
 * ┗--------------------
 */

public class RetrofitUtils {

    public static MultipartBody.Part createPart(String key, String value) {
        return MultipartBody.Part.createFormData(key, value);
    }

    public static MultipartBody.Part createImagePart(String key, File file) {
        RequestBody body = RequestBody.create(MediaType.parse("image/png"), file);
        return MultipartBody.Part.createFormData(key, file.getName(), body);
    }

    public static MultipartBody.Part createImagePart(String key, String filePath) {
        if (filePath == null || filePath.isEmpty())
            return null;
        File file = new File(filePath);
        RequestBody body = RequestBody.create(MediaType.parse("image/png"), file);
        return MultipartBody.Part.createFormData(key, file.getName(), body);
    }

}
